package beans;

import java.util.ArrayList;
import java.util.List;

import models.Article;
import models.ArticleComment;
import models.Photo;
import models.User;

public class ArticleCommentBean {
	public String content;
	public String nickName;
	public String url;
	public long time;
	
	public static ArticleCommentBean build(ArticleComment ac)
	{
		ArticleCommentBean bean = new ArticleCommentBean();
		bean.content = ac.comment;
		bean.time = ac.createTime;
        User user = null;
		if(ac.type == ArticleComment.VISITOR)
			bean.nickName = "游客";
		else{
            bean.nickName = User.getAuthorNameById(ac.commentId);
            user = User.findById(ac.commentId);
        }

		if(user != null)
		{
			Photo photo = Photo.find("id = ?",user.photoId).first();
			if(photo != null)
			{
				bean.url = photo.getPhoto();
			}
			else
				bean.url = "../public/images/tt.png";
		}
        else{
            bean.url = "../public/images/tt.png";

        }
		return bean;
	}
	
	public static List<ArticleCommentBean> buildList (List<ArticleComment> plist){
        List<ArticleCommentBean> endlist = new ArrayList<ArticleCommentBean>();
        for(int item = 0;item<plist.size();item++){
            ArticleCommentBean bean = ArticleCommentBean.build(plist.get(item));
            endlist.add(bean);
        }
        return endlist;
    }
}
